<?php
	$arrParam 	= $this->arrParam;
	
	$arrFilter 	= $this->arrParam['arrFilter'];
	
	$statusOption = array('none'=>'-- ' . $this->translate('Status') . ' --',
						  'active'=>$this->translate('Active'),
						  'inactive'=>$this->translate('Inactive'),
						 );
	$classStatus 	= (empty($arrFilter['status']) || $arrFilter['status'] == 'none')? 'width-150': 'width-150 bg-green2';						 
	$slbStatus 		= $this->formSelect('status',$arrFilter['status'],array('class'=>$classStatus),$statusOption);
	
	$lnkFiter 	= $this->url(array('action'=>'filter','type'=>'filter'));
	$btnFiter 	= $this->formButton('submit-filter',$this->translate("Filter"),
								array('class'=>'button','onclick'=>"onSubmitForm('appForm','" . $lnkFiter . "')"));
	
	$levelOption 	= array(' -- All Level -- ',' -- Level 1 -- ',' -- Level 2 -- ',' -- Level 3 -- ',
							' -- Level 4 -- ',' -- Level 5 -- ',' -- Level 6 -- ',' -- Level 7 -- ',
							' -- Level 8 -- ',' -- Level 9 -- ',' -- Level 10 -- ');
	$classLevel 	= (!isset($arrFilter['level']) || $arrFilter['level'] == '0')? 'width-150': 'width-150 bg-green2';
	$slbLevel 		= $this->formSelect('level',$arrFilter['level'],array('class'=>$classLevel),$levelOption);
	
	$classParent 	= (!isset($arrFilter['parentNode']) || $arrFilter['parentNode'] == 1)? 'width-150': 'width-150 bg-green2';
	$slbParentNode 	= $this->cmsSelect('parentNode',$arrFilter['parentNode'],array('class'=>$classParent),$this->slbLevel);
	
	$strFilter 		= $slbLevel . ' ' . $slbParentNode . ' ' . $slbStatus . ' ' . $btnFiter;
	
	/*===============================================
	 * Start - Loc theo cac cot
	 *===============================================*/	
	$clsKeyword = $arrFilter['keyword']?'width-150 bg-green2':'width-150';
	$keyword 	= $this->formText('keyword',$arrFilter['keyword'],array('class'=>$clsKeyword));
	$slbSearchFiels = array(
							'c.name'=>$this->translate('- Name'),
							'c.id'=>$this->translate('- ID'),
							'c.created'=>$this->translate('- Created'),
							'u1.email'=>$this->translate('- Created by'),
							'c.modified'=>$this->translate('- Modified'),
							'u2.email'=>$this->translate('- Modified by'),
							'c.description'=>$this->translate('- Description'),
							);
	$slbFiels	= $this->formSelect('search-field',$arrFilter['searchField'],array('class'=>'width-150'),$slbSearchFiels);
	
	$lnkGo 		= $this->url(array('action'=>'filter','type'=>'search'));
	$btnGo 		= $this->formButton('search',$this->translate("Search"),
								array('onclick'=>"onSubmitForm('appForm','" . $lnkGo . "')",'class'=>'button'));
								
	$lnkClear 	= $this->url(array('action'=>'filter','type'=>'clear'));
	$btnClear 	= $this->formButton('clear',$this->translate("Clear"),
								array('onclick'=>"onSubmitForm('appForm','" . $lnkClear . "')",'class'=>'button'));
								
	$strSearch = '<b>' . $this->translate('Keywords') . ':</b> ' 
				 . $keyword . ' ' . $slbFiels . ' ' . $btnGo . ' ' . $btnClear;

?>

<?php echo $this->render($this->includeDir . '/toolbar.php');?>
<?php echo $this->flashMessage();?>
<div id="element-box">
            <div class="m">
            	<div class="filter-result">
            		<div style="float: left;">
            			 <?php echo $strSearch;?>
	                </div>
	                <div style="float: right;">
            			<?php echo $strFilter;?>
            		</div>
            		<div class="clr"></div>
            	</div>
            	
                <div class="div-table">
                <table width="100%" border="0" class="adminlist">
                <thead>
                	 <?php 
                	 	$lblName 		= $this->translate('Name');
                	 	$lblStatus 		= $this->translate('Status');
                	 	$lblCreated		= $this->translate('Created');
                	 	$lblCreatedBy	= $this->translate('Created by');
                	 	$lblModified	= $this->translate('Modified');
                	 	$lblModifiedBy	= $this->translate('Modified by');
                	 	$lblRouter 		= $this->translate('Type');
                	 	$lblOrdering 	= $this->translate('Sort');
                	 	$lblControl		= $this->translate('Control');
                	 	$lblID 			= $this->translate('ID');
 
                	 	require 'includes/row-thead.php';
                	 	
                	 ?>
                     
                 </thead>
                 <tbody>
                 <?php 
                 	
                 	if(count($this->Items)> 1){
                 		$i = 1;
                 		
                 		foreach ($this->Items as $key => $val){   
                 		
                 			if($val['parents'] == 0){
                 				unset($result[$k]);
                 				continue;
                 			}
                 			$cssTR = 'odd';
                 			if($i%2==0) $cssTR = 'even';
                 			$name = Zendvn_Filter_Filter::filterContent($val['name'],'filter');
                 			if($val['level'] == 1){
								$name 	= '<div> + ' . $name . '</div>';
							}else{
								$x 		= 40 * ($val['level']-1);
								$css 	= 'padding-left: ' . $x . 'px;';
								$name 	= '<div style="' . $css . '">- ' . $name . '</div>';
							}
                 			$id 			= $val['id'];
                 			$cid 			= $this->formCheckbox('cid[]',$val['id']);
                 			$router 		= Zendvn_Filter_Filter::filterContent($val['router'],'filter');
                 			
							$orderingName 	= 'ordering[' . $val['lft'] . ']';
							$orderValue		=  $this->tblCate->getNodeOrdering($val['parents'],$val['lft']);
							$orderCss 		= ($val['level'] == 1)?array('class'=>'width-50 bg-green center'):array('class'=>'width-50 center');
							$ordering 		= $this->formText($orderingName,$orderValue,$orderCss);
							
							$attribs = array('icon'=>'inactive.png','iconDir' => "images/small-icons/");
							if($val['status'] == 'active')$attribs['icon'] = 'active.png';
							$lnkStatus  = $this->url(array('action'=>'status','id'=> $val['id'],'s'=>$val['status']));
							$status 	= $this->cmsIcon('Trạng thái',$lnkStatus,$attribs);
							
                 			$created 		= $val['created'];
                 			$createdby 		= $val['created_by'];
                 			$modified 		= $val['modified'];
                 			$modifiedBy		= $val['modified_by'];
                 			
                 			$control = '---';
							$iconDel = '';
							if($val['group_default'] != 1){
								$lnkDel  = $this->url(array('action'=>'delete','id'=> $val['id']));
								$options = array('type'=>'submit','name'=>'appForm',
												 'notice'=>$this->translate('Are you sure you want to delete this item?'));
								$iconDel = $this->cmsIcon('Delete',$lnkDel,array('icon'=>'icon-delete.png'),$options);
							}
							
							$lnkInfo  	= $this->url(array('action'=>'info','id'=> $val['id']));
							$iconInfo 	= $this->cmsIcon('Info',$lnkInfo,array('icon'=>'icon-info.png'));
												
							$lnkEdit  	= $this->url(array('action'=>'edit','id'=> $val['id']));
							$iconEdit 	= $this->cmsIcon('Edit',$lnkEdit,array('icon'=>'icon-edit.png'));
												
							$control 	= $iconInfo . ' ' . $iconEdit . ' ' . $iconDel;
												
							$id = $val['id'];
                    		
                			require 'includes/row-tbody.php';
                			$i++;
                 		}
                 	}else{
                 		echo $this->render('empty.php');
                 	}
                  ?>
                  </tbody>
                  <tfoot>
                      <tr>
                        <td colspan="15">
                        	<?php echo $this->paginationControl($this->panigator,'Sliding','paning.php',array('arrParam'=>$arrParam));?>
                        </td>
                      </tr>
                  </tfoot>
                </table>

                </div>
            </div>
         </div>